import React from 'react'
import { Spin } from 'antd';
import { WeaAlertPage, WeaLocaleProvider } from "ecCom";
import weaBlogDict from '../../../Component/wea-blog-dict';
import AttentionApi from '../../../../apis/myAttention';
import AttentionTool from '../../../MyAttention/AttentionTool';
const innerHref = weaBlogDict.href;
const getLabel = WeaLocaleProvider.getLabel;

class WeiboNormalPermissions extends React.Component {
	constructor(props) {
		super(props);
		let funcs = ['getBlogInfo'];
		funcs.forEach((func) => this[func] = this[func].bind(this));
		this.state = {
			blogInfo: undefined,
			index: undefined
		};
	}

	componentDidMount() {
		this.getBlogInfo();
	}
	// componentWillReceiveProps(nextProps) {
	// 	let userId = this.props.user.id;
	// 	this.setState({
	// 		blogInfo: undefined,
	// 		index: undefined
	// 	}, () => this.getBlogInfoByUserId(userId));
	// }
	getBlogInfo() {
		this.getBlogInfoByUserId(this.props.user.id);
	}
	getBlogInfoByUserId(userId) {
		if (!userId) return;
		AttentionApi.getBlogPersonalInfo({ blogId: userId }).then((result) => {
			this.setState({ blogInfo: result });
			if (this.props.changeTitle) {
				document.title = result.username + getLabel('384490', "的微博");
			}
			// 有权限展示时才显示指数
			if (result.viewStatus > 0) {
				AttentionApi.getBlogWorkIndex({ blogId: userId }).then((result) => {
					this.setState({ index: result })
				}).catch(error => message.error(error));
			}
		}).catch(error => message.error(error));
	}
	render() {
		const { data, id, keyWords, user } = this.props;
		let blogInfo = this.state.blogInfo;
		if (!blogInfo)
			return (
				<div className="align-center top40">
					
				</div>);
		return (
			<div>

				{blogInfo.viewStatus == -1 ?
					<div className="color-black icon-coms-locking" style={{ textAlign: "center", padding: "0 0 65px 0" }}>
						{getLabel('384491', "你当前不具有对")}
						<a href={innerHref.user(blogInfo.userId)} target="_blank">{blogInfo.username}</a>
						{getLabel('384492', "工作微博的查看权限，请联系对方将微博分享给你！")}
					</div> : blogInfo.viewStatus == 0 ?
					<div>
						<div className="icon-coms-locking color-black" style={{ textAlign: "center" }} >
							{getLabel('384491', "你当前不具有对")}
							<a href={innerHref.user(user.id)} target="_blank">{user.name}</a>
							{getLabel('384493', "工作微博的查看权限，请联系对方将微博分享给你，或向他发关注申请！")}
						</div>
						<div className="msgTool" style={{textAlign: "center"}}>
							<AttentionTool ecId={`${this && this.props && this.props.ecId || ''}_AttentionTool@w13xru`} isreceive={blogInfo.isreceive} attentionStatus={blogInfo.attentionStatus} islower={blogInfo.islower} userId={blogInfo.userId} callback={this.getBlogInfo} />
						</div>
					</div> : ""
				}
			</div>
		);
	}
}

export default WeiboNormalPermissions